//
//  TGMasterListViewController.m
//  WanCaiC8
//
//  Created by QiuXun on 2019/1/16.
//  Copyright © 2019 tangang. All rights reserved.
//

#import "TGMasterListViewController.h"
#import "LotteryNavTypeView.h"

#import "RankCell.h"
#import "RankingTotalTopCollectionViewCell.h"
#import "InformationVM.h"
#import "HomePageVM.h"
#import "MasterListVC.h"

#import "Home_TypeView.h"

#import "TGPlanRankingCollectionViewCell.h"
#import "TGAdvertCollectionReusableView.h"
#import "TGMastMoreCollectionViewCell.h"
#import "PlanPeopleVC.h"


@interface TGMasterListViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic ,strong) LotteryNavTypeView *lotteryNavTypeView;
@property (nonatomic ,strong) UICollectionView *collectionView;

@property (nonatomic ,assign) NSInteger selectLottery;

@property (nonatomic ,strong)MasterListVC *masterListVC;

//开奖首页-彩种分类 不带时间
@property (nonatomic ,strong)NSArray *lotteryList;
//记录 二级彩种分类 带倒计时
@property (nonatomic ,strong)NSMutableArray *secondLotteryList;


/**
 是否显示planVC
 */
@property (nonatomic ,assign)BOOL isShowMasterList;


@property (nonatomic ,strong) Home_TypeView *home_TypeView;

@property (nonatomic ,strong) NSArray   *ruleArr;
@property (nonatomic ,strong) NSArray   *subRuleArr;
@property (nonatomic ,assign) NSInteger selectRule;
@property (nonatomic ,assign) NSInteger selectSubRule;




//记录首页进入的高手计划
@property (nonatomic ,assign) NSInteger tempSelectRule;
//记录首页进入的高手计划
@property (nonatomic ,assign) NSInteger tempSelectSubRule;



//Home MasterList
@property (nonatomic ,strong) NSArray *hotMasterArr;


@property (nonatomic ,strong) NSArray *navArr;


@property (nonatomic ,strong) NSMutableArray *arr1;
@property (nonatomic ,strong) NSMutableArray *arr2;
@property (nonatomic ,strong) NSMutableArray *colArr1;
@property (nonatomic ,strong) NSMutableArray *colArr2;


@end

@implementation TGMasterListViewController

#pragma mark - 接收通知
-(void)receiveNotification{
    NSLog(@"___________>接收到通知");
    LotteryTypeModel *model = self.navArr[self.selectLottery];
    [self getIndexLotteryListWithParentId:model.Id];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"TGReloadData" object:nil];
    
    self.selectLottery = -1;
    self.title = @"彩票高手计划";
    self.masterListVC.view.hidden = YES;
 
    
    [self setRightNavItem];
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [self getNewIndexLotteryList];
        [self getNavLotteryTypeList];
        [self getAdvertising];
    });
    
    
    [self.collectionView reloadData];

    
    if (_tempPlayRuleModel) {
        
        self.tempSelectSubRule =0;
        self.tempSelectRule = 0;
        
        self.isShowMasterList = YES;
        self.masterListVC.view.hidden = NO;
        // playRuleModel
        //  例如Name=大小  Id=772,ParentId=770,sort=0,ltype=5;
        self.strTitle= @"六合彩";
        self.masterListVC.strTitle = @"六合彩";
        [self getPlayTypeWithLType:[NSString stringWithFormat:@"%ld",self.tempPlayRuleModel.lType]];
    }
   
}


-(void)setRightNavItem{
    
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(onclickNav)];
    self.navigationItem.rightBarButtonItem=rightItem;
    
}



#pragma mark -- 获取广告
- (void)getAdvertising{
    
    
    WS(weakSelf);
    
    self.arr1 = [NSMutableArray array];
    self.arr2 = [NSMutableArray array];
    self.colArr1 = [NSMutableArray array];
    self.colArr2 = [NSMutableArray array];
    
    [[InformationVM manage] getAdvertWithLocation:@"0" andType:6 Success:^(id returnValue) {
        
        for (AdvertisingModel *model in returnValue) {
            if (model.Layer == 1) {
                
                [weakSelf.arr1 addObject:model];
                
                if (model.IsDisplay) {
                    [weakSelf.colArr1 addObject:model];
                }
            }
            if (model.Layer == 2) {
                
                [weakSelf.arr2 addObject:model];
                if (model.IsDisplay) {
                    [weakSelf.colArr2 addObject:model];
                }
            }
        }
        
        
        [self insertAdvertising];
        
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
    //    }
}
#pragma mark - 插入广告 //
-(void)insertAdvertising{
    
    
    
//    if (self.lotteryList.count>2&&self.arr2.count>0) {
//
//        [self.lotteryList insertObject:self.arr2 atIndex:2];
//    }
    //    if (self.dataArr.count>6&&arr6.count>0) {
    //        [self.dataArr insertObjects:arr6 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(6, arr6.count)]];
    //    }
    
    [self.collectionView reloadData];
    
}

#pragma mark --  获取二级彩种分类
-(void)getIndexLotteryListWithParentId:(NSString *)parentId{
    
    [SVProgressHUD show];
    
    
    [[HomePageVM manage] getHomeLotteryList:parentId andSuccess:^(id returnValue) {
        
        [SVProgressHUD dismiss];
        [self.secondLotteryList removeAllObjects];
        [self.secondLotteryList addObjectsFromArray:returnValue];
        
        [self.collectionView reloadData];
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
    
    
}
#pragma mark -- 获取彩票导航分类
- (void)getNavLotteryTypeList{
   
        WS(weakSelf);
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [[HomePageVM manage] getLotteryTypeListWithParentId:@"0" Success:^(id returnValue) {
                self.navArr = [NSArray arrayWithArray:returnValue];
                
                if (self.navArr.count>0) {
                    [_lotteryNavTypeView setDataArr:self.navArr];
                }
                
            } Fail:^(NSString *errorMessage, NSError *error) {
                
            }];
        });
  
}


#pragma mark --  获取新首页彩种信息列表
- (void)getNewIndexLotteryList{
    
    [[InformationVM manage] getNewIndexLotteryListSuccess:^(id returnValue) {
        
        self.lotteryList= [NSArray arrayWithArray:returnValue];
        
        
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
             [self getData];
        });
       
        
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}


#pragma mark - collectionView代理函数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    if (self.selectLottery == -1) {
        return 1+(self.hotMasterArr.count?1:0)+(self.lotteryList.count?1:0);
    }else{
        return 1;
    }
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    if (self.selectLottery == -1) {
        
        if (section ==0) {
            return 1;
        } else if(section ==1){
            return self.hotMasterArr.count+1;
        }else{
            return  self.lotteryList.count;
        }
        
    } else {
        return self.secondLotteryList.count;
        
    }
    
    
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.selectLottery == -1) {
        if (indexPath.section == 0) {
            RankingTotalTopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RankingTotalTopCollectionViewCell" forIndexPath:indexPath];

            return cell;
        } else if(indexPath.section==1){
            
            if (indexPath.row<self.hotMasterArr.count) {
                
                TGPlanRankingCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TGPlanRankingCollectionViewCell" forIndexPath:indexPath];
                cell.model=self.hotMasterArr[indexPath.row];
                if (self.arr2.count&&indexPath.row==1) {
                    [cell setModelArr:self.arr2 AndRowCount:(NSInteger)(self.arr2.count-ceil(self.colArr2.count/2.0))];
                }else{
                     [cell setModelArr:nil  AndRowCount:0];
                }
                return cell;
                
            }else{
                
                TGMastMoreCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"TGMastMoreCollectionViewCell" forIndexPath:indexPath];
                
                return cell;
                
            }
            
        }else{
            
            RankCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RankCell" forIndexPath:indexPath];
            
            cell.model = self.lotteryList[indexPath.row];
            
            return cell;
        }
        
        
    }else {
        
        RankCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RankCell" forIndexPath:indexPath];
        
        cell.home_LotteryModel = self.secondLotteryList[indexPath.row];
        
        return cell;
        
        
    }
    

    
}



//
//- (UICollectionViewCell *)cellWithModel:(AdvertisingModel *)model andIndexPath:(NSIndexPath *)indexPach{
//
//}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    if (self.selectLottery == -1) {

        if (indexPath.section == 0) {
            return CGSizeMake(SCREEN_WIDTH, 125);
        } else if(indexPath.section == 1){
            
           
            if (indexPath.row<self.hotMasterArr.count) {
                if (indexPath.row==1&&self.arr2.count) {
                    return CGSizeMake(SCREEN_WIDTH, 80+40*self.arr2.count-40*ceil(self.colArr2.count/2.0));
                }else{
                    return CGSizeMake(SCREEN_WIDTH, 80);
                }
            }else{
                return CGSizeMake(SCREEN_WIDTH, 40);
            }
            
        }else{
            return CGSizeMake(SCREEN_WIDTH/2.0, SCREEN_WIDTH/5.0);
        }

    }else{
        
        return CGSizeMake(SCREEN_WIDTH/2.0, SCREEN_WIDTH/5.0);
        
    }
    
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section ==0 ||section ==2) {
        return CGSizeZero;
    }else{
        if (self.arr1.count) {
            return CGSizeMake(SCREEN_WIDTH, self.arr1.count*40-ceil(self.colArr1.count/2.0)*40+10);
        }else{
            return CGSizeZero;
        }
    }
    
}

- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    UICollectionReusableView *reusableView = nil;
    
    if (kind == UICollectionElementKindSectionHeader)
    {
        if (indexPath.section ==1) {
            TGAdvertCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"TGAdvertCollectionReusableView" forIndexPath:indexPath];
            if (self.arr1.count) {
                [headerView setAdModelArr:self.arr1 AndRowCount:(NSInteger)(self.arr1.count-ceil(self.colArr1.count/2.0))];
            }
            
            reusableView = headerView;
        }else{
            return nil;
        }
        
    }
    return reusableView;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    if(!self.navArr.count){
        return;
    }
    
    if (self.selectLottery == -1) {
        if (indexPath.section==1) {
            if (indexPath.row<self.hotMasterArr.count) {
               
                ExpertsModel *eModel=self.hotMasterArr[indexPath.row];
                PlanPeopleVC *vc=[[PlanPeopleVC alloc]init];
                LotteryTypeModel *lotteryModel=[[LotteryTypeModel alloc]init];
                lotteryModel.lType=eModel.lType;
                vc.lotteryModel=lotteryModel;
                vc.model=eModel;
                vc.playName=eModel.PlayName;
                vc.title=@"6彩近期竞彩";
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                
                
                
                self.lotteryNavTypeView.isHomeEnter = YES;
                self.lotteryNavTypeView.selectLottery = 0;
                
                //   self.title =[NSString stringWithFormat:@"%@开奖记录",model.LTypeName];
                
                self.isShowMasterList = YES;
                self.masterListVC.view.hidden = NO;
                
            
                self.strTitle = @"六合彩";
                self.masterListVC.strTitle =self.strTitle;
                
                [self getPlayTypeWithLType:@"5"];
                
                
                
            }
           
        }
        if (indexPath.section == 2) {
            RankListModel *model =  self.lotteryList[indexPath.row];
            NSArray *arr = self.navArr.copy;
            NSInteger temp=0;
            for (int i= 0; i<arr.count; i++) {

                LotteryTypeModel *lotteryTypeModel = arr[i];
                if ([model.BigLType integerValue] == [lotteryTypeModel.lType integerValue]) {
                    temp= i;
                }
            }

            self.lotteryNavTypeView.isHomeEnter = YES;
            self.lotteryNavTypeView.selectLottery = temp;

//   self.title =[NSString stringWithFormat:@"%@开奖记录",model.LTypeName];
           
            self.isShowMasterList = YES;
            self.masterListVC.view.hidden = NO;
            
            
//            LotteryTypeModel *lotteryTypeModel  = self.navArr[self.selectLottery];
//
            
            self.strTitle= model.LTypeName;
            self.masterListVC.strTitle =self.strTitle;

            
            [self getPlayTypeWithLType:model.LType];
 

        }
    }else{
        
        Home_LotteryModel *model=self.secondLotteryList[indexPath.row];
        self.lotteryNavTypeView.isHomeEnter = YES;
   
        
        self.isShowMasterList = YES;
        self.masterListVC.view.hidden = NO;
        self.strTitle= model.LTypeName;
        self.masterListVC.strTitle =self.strTitle;

        [self getPlayTypeWithLType:model.LType];
    
    }

    
}


#pragma mark - 懒加载
- (LotteryNavTypeView *)lotteryNavTypeView{
    if (!_lotteryNavTypeView) {
        WS(weakSelf);
        _lotteryNavTypeView=[[LotteryNavTypeView alloc] init];

        [self.view addSubview:_lotteryNavTypeView];
        [_lotteryNavTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(weakSelf.view);
            make.height.mas_equalTo(@40);
        }];
        
        if (_tempPlayRuleModel) {
            _lotteryNavTypeView.isNewMaster = YES;
            _lotteryNavTypeView.selectLottery = 0;
        }
        
        _lotteryNavTypeView.chaneBlock = ^(NSInteger row) {

    
            weakSelf.selectLottery=row;
            
            weakSelf.selectRule = 0;
            
            if (row!=-1) {
                LotteryTypeModel *model = weakSelf.navArr[row];
                if (model.SonIdArr.count>1) {
                    
                    weakSelf.navigationItem.titleView=nil;
                    weakSelf.title = [NSString stringWithFormat:@"%@高手计划",model.Name];
                  
                    weakSelf.isShowMasterList = NO;
                    weakSelf.masterListVC.view.hidden = YES;
                    [weakSelf getIndexLotteryListWithParentId:model.Id];
                    
                } else {

                    weakSelf.isShowMasterList = YES;
                    weakSelf.masterListVC.view.hidden = NO;
    
                    
                    weakSelf.strTitle= model.Name;
                    
                    weakSelf.masterListVC.strTitle = weakSelf.strTitle;
                    
                    //获取顶部导航的rullarr
                    
                    [weakSelf getPlayTypeWithLType:model.SonIdArr.firstObject];
                    
                    
//
//            weakSelf.openRecordVC.lType = model.SonIdArr.firstObject;
//            weakSelf.openRecordVC.lotteryType = [[BaseVM manage] getType:[model.SonIdArr.firstObject integerValue]];
                }
                
            }else{
                
                weakSelf.navigationItem.titleView=nil;
                weakSelf.title = @"彩票高手计划";
                weakSelf.isShowMasterList = NO;
                weakSelf.masterListVC.view.hidden = YES;
                [weakSelf.collectionView reloadData];
            }
            
        };
        
        
    }
    return _lotteryNavTypeView;
}

- (UICollectionView *)collectionView{
    if (_collectionView==nil) {
        WS(weakSelf);
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        
        [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
        layout.minimumInteritemSpacing = 0.0;
        layout.minimumLineSpacing = 0.0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor=[UIColor whiteColor];
        _collectionView.showsVerticalScrollIndicator=NO;
        
        [_collectionView registerClass:[RankingTotalTopCollectionViewCell class] forCellWithReuseIdentifier:@"RankingTotalTopCollectionViewCell"];
        
        [_collectionView registerClass:[TGPlanRankingCollectionViewCell class] forCellWithReuseIdentifier:@"TGPlanRankingCollectionViewCell"];
        [_collectionView registerClass:[TGMastMoreCollectionViewCell class] forCellWithReuseIdentifier:@"TGMastMoreCollectionViewCell"];
      
        [_collectionView registerClass:[RankCell class] forCellWithReuseIdentifier:@"RankCell"];
        
        
        [_collectionView registerClass:[TGAdvertCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"TGAdvertCollectionReusableView"];
        
        
        [self.view addSubview:_collectionView];
        [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.view);
            make.top.equalTo(self.lotteryNavTypeView.mas_bottom);
        }];

        //        _collectionView.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            weakSelf.page=1;
        //            [weakSelf.dataArr removeAllObjects];
        //            [weakSelf.tableView reloadData];
        //            [weakSelf getData];
        //        }];
        //        _tableView.footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        //            [weakSelf getData];
        //        }];
    }
    return _collectionView;
}




- (NSMutableArray *)secondLotteryList{
    if (!_secondLotteryList) {
        _secondLotteryList=[[NSMutableArray alloc]init];
    }
    return _secondLotteryList;
}

//第二个控制器

- (MasterListVC *)masterListVC{
    if (!_masterListVC) {
        WS(weakSelf);
        
        _masterListVC=[[MasterListVC alloc] init];
        [self.view insertSubview:_masterListVC.view aboveSubview:self.collectionView];
        [_masterListVC.view setFrame:CGRectMake(0, 40, SCREEN_WIDTH, SCREEN_HEIGHT-40)];
        _masterListVC.view.hidden=YES;
        [self addChildViewController:_masterListVC];
    }
    return _masterListVC;
}

- (NSArray *)ruleArr{
    
    if (!_ruleArr) {
        _ruleArr = [NSMutableArray array];
    }
    return _ruleArr;
}


- (UIButton *)navTitleBtnWithStr:(NSString *)str{

    
    PlayRuleModel *playRuleModel;
    
    if(_tempPlayRuleModel){
        playRuleModel = self.ruleArr[self.tempSelectRule];
    }else{
       playRuleModel= self.ruleArr[self.selectRule];
    }
//
//    LotteryTypeModel *lotteryTypeModel  = self.navArr[self.selectLottery];
    
    NSString *title = [NSString stringWithFormat:@"%@-%@", str,playRuleModel.Name];
//    }else{
//        title =  [NSString stringWithFormat:@"%@-%@",self.strTitle,self.dic[@"title"]];
//    }

    
    CGFloat width=[TGTools boundingRectWithString:title withWidth:300 anfont:[UIFont boldSystemFontOfSize:19]];
    UIButton *_navTitleBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, width+30, 30)];
    [_navTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _navTitleBtn.titleLabel.font=[UIFont boldSystemFontOfSize:19];
    [_navTitleBtn setTitle:title forState:UIControlStateNormal];
    [_navTitleBtn setImage:[UIImage imageNamed:@"white_angle"] forState:UIControlStateNormal];
    [_navTitleBtn verticalImageAndTitle:width andImage:[UIImage imageNamed:@"white_angle"]];
    _navTitleBtn.layer.masksToBounds=YES;
    _navTitleBtn.layer.cornerRadius=2;
    _navTitleBtn.layer.borderColor=[UIColor whiteColor].CGColor;
    _navTitleBtn.layer.borderWidth=1;
    [_navTitleBtn addTarget:self action:@selector(onclickType:) forControlEvents:UIControlEventTouchUpInside];
    return _navTitleBtn;
}

#pragma mark -- 点击顶部彩种分类
- (void)onclickType:(UIButton *)sender{
    
//    self.dic = nil;
    if (self.home_TypeView) {
        [self.home_TypeView remove];
        self.home_TypeView=nil;
        return;
    }
    WS(weakSelf);
    self.home_TypeView=[[Home_TypeView alloc]init];
    [self.home_TypeView setArr:self.ruleArr andIndex:self.selectRule andSelectBlock:^(NSInteger row) {
        if (weakSelf.selectRule!=row) {
            weakSelf.selectRule=row;
            
            PlayRuleModel *model = weakSelf.ruleArr.firstObject;
            [weakSelf getSubPlayTypeWithLType:[NSString stringWithFormat:@"%ld",model.lType]];
            weakSelf.navigationItem.titleView=[weakSelf navTitleBtnWithStr:weakSelf.strTitle];
        }
        weakSelf.home_TypeView=nil;
    }];
    [self.view addSubview:self.home_TypeView];
    [self.home_TypeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(weakSelf.view);
    }];
}

#pragma mark -- 获取玩法分类
- (void)getPlayTypeWithLType:(NSString *)lType{
    WS(weakSelf);

    
    [SVProgressHUD show];
    [[InformationVM manage] getRuleListWithLType:lType andParentId:0 Success:^(id returnValue) {
        weakSelf.ruleArr=returnValue;

    
        
        for (int i = 0; i<weakSelf.ruleArr.count; i++) {
            
            PlayRuleModel *model = weakSelf.ruleArr[i];
            if (self.tempPlayRuleModel.ParentId == model.Id) {
                self.tempSelectRule = i;
                break;
            }
        }

        
        weakSelf.navigationItem.titleView=[weakSelf navTitleBtnWithStr:self.strTitle];
        [weakSelf getSubPlayTypeWithLType:lType];
    } andFail:^(NSString *errorMessage, NSError *error) {

    }];
}

#pragma mark -- 获取子玩法分类
- (void)getSubPlayTypeWithLType:(NSString *)lType{
    WS(weakSelf);
    PlayRuleModel *model;
    
    if (_tempPlayRuleModel) {
        model =self.ruleArr[self.tempSelectRule];
    }else{
        model= self.ruleArr[self.selectRule];
    }

    [[InformationVM manage] getSubRuleListWithLType:lType andParentId:model.Id Success:^(id returnValue) {
        
        [SVProgressHUD dismiss];
        
        weakSelf.subRuleArr=returnValue;
        for (int i = 0; i<weakSelf.subRuleArr.count; i++) {
            PlayRuleModel *model = weakSelf.subRuleArr[i];
            NSLog(@"%@--%@",model.Name,model.PlayName);
            if (self.tempPlayRuleModel.Id == model.Id) {
                self.tempSelectSubRule = i;
                break;
            }
        }
        
        if (_tempPlayRuleModel) {
            [self.masterListVC setRuleArr:_ruleArr WithSubRuleArr:_subRuleArr WithselectRule:self.tempSelectRule WithSelectSubRule:self.tempSelectSubRule];
            //重置
            _tempPlayRuleModel = nil;
        }else{
            [self.masterListVC setRuleArr:_ruleArr WithSubRuleArr:_subRuleArr WithselectRule:self.selectRule WithSelectSubRule:self.selectSubRule];
        }
        
    
        [weakSelf.masterListVC hiddenCollectionView];
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}



//
- (void)getData{
    WS(weakSelf);
   
    [[InformationVM manage] getMasterListWithLType:@"5" andPlayName:nil andPage:1 Success:^(id returnValue) {

        self.hotMasterArr =returnValue;
        //赋值给collection
        [self.collectionView reloadData];
        
    } andFail:^(NSString *errorMessage, NSError *error) {
       
    }];
}



- (void)dealloc
{
    
    NSLog(@"TGmaster   销毁");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"TGReloadData" object:self];
}

@end
